﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.BLL;
using BDCS.Model;

namespace BDCS.UI
{
    public partial class AddBuildDesignDcriterionSubTypes : Form
    {
        #region 成员字段
        private BDCS.BLL.T_BuildDesignDcriterionTypes bllBuildDesignDcriterionTypes;
        private BDCS.BLL.T_BuildDesignDcriterionSubTypes bllBuildDesignDcriterionSubTypes;
        private BDCS.Model.T_BuildDesignDcriterionSubTypes modelBuildDesignDcriterionSubTypes;
        private DataSet dataSet; 
        #endregion
        #region 构造函数
        public AddBuildDesignDcriterionSubTypes()
        {
            InitializeComponent();
        } 
        #endregion
        #region 成员事件
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtBuildDesignDcriterionSubTypeName.Text.Trim()))
            {
                MessageBox.Show("请输入规范子类名称！");
            }
            else
            {
                if (this.txtBuildDesignDcriterionSubTypeName.Text.Length <= 50)
                {
                    bllBuildDesignDcriterionSubTypes = new BLL.T_BuildDesignDcriterionSubTypes();
                    dataSet = new DataSet();
                    dataSet = bllBuildDesignDcriterionSubTypes.GetList("DSTName=" + "'" + this.txtBuildDesignDcriterionSubTypeName.Text.Trim() + "'");
                    if (dataSet.Tables[0].Rows.Count == 0)
                    {
                        modelBuildDesignDcriterionSubTypes = new Model.T_BuildDesignDcriterionSubTypes();
                        modelBuildDesignDcriterionSubTypes.DSTName = this.txtBuildDesignDcriterionSubTypeName.Text.Trim();
                        modelBuildDesignDcriterionSubTypes.DSTDescribe = this.txtBuildDesignDcriterionSubTypeDescribe.Text.Trim();
                        modelBuildDesignDcriterionSubTypes.DTID = Convert.ToInt32(this.cobBuildDesignDcriterionTypeName.SelectedValue);
                        bllBuildDesignDcriterionSubTypes = new BLL.T_BuildDesignDcriterionSubTypes();
                        if (bllBuildDesignDcriterionSubTypes.Add(modelBuildDesignDcriterionSubTypes) != 0)
                        {
                            BDCS.Common.TreeViewState.IsChangedDcriterion = true;
                            MessageBox.Show("添加子类规范名称成功！");
                        }
                        else
                        {
                            MessageBox.Show("添加子类规范名称失败，请重新输入！");
                        }
                    }
                    else
                    {
                        MessageBox.Show("输入的规范子类别名称已经存在，请重新输入！");
                    }
                }
                else
                {
                    MessageBox.Show("输入内容长度大于50，请重新输入！");
                }
            }
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtBuildDesignDcriterionSubTypeName.Text = string.Empty;
            this.txtBuildDesignDcriterionSubTypeDescribe.Text = string.Empty;
        }
        private void AddBuildDesignDcriterionSubTypes_Load(object sender, EventArgs e)
        {
            ComboxDataBinding();
        } 
        #endregion
        #region 成员方法
        private void ComboxDataBinding()
        {
            bllBuildDesignDcriterionTypes = new BLL.T_BuildDesignDcriterionTypes();
            dataSet = new DataSet();
            dataSet = bllBuildDesignDcriterionTypes.GetAllList();
            this.cobBuildDesignDcriterionTypeName.DataSource = dataSet.Tables[0];
            this.cobBuildDesignDcriterionTypeName.DisplayMember = "DTName";
            this.cobBuildDesignDcriterionTypeName.ValueMember = "DTID";
        }
        #endregion
    }
}
